--
-- Author: shunguo.chen
-- Date: 2018-02-06 14:55:02
--
-- ZoneInfo 地图区域基本信息

local Fame = require("app.public.dao.Fame")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
    if data then
        self:init(data)
    end
end

-- data = conf 区域配置
function ClassRef:init(data) 
	self._conf = data

	self.id = tonumber(data.ID)
	self.mapId = tonumber(data.map)

	self._startPos = tonumber(data.startPoint)
	self._endPos = tonumber(data.endPoint)
	self._resetPos = tonumber(data.resetPoint)
	self._icon = nil
	self._bg = nil

	self._npcs = nil
	-- self._levDatas = table.tonumber(string.split(self._conf.prosperityLv, "|"))

	self.blessExpMax = tonumber(self._conf.prosperitySum)
end

-- 是自己目前所在区域
function ClassRef:isCurZone()
	local posX = FieldManager:getCharacterX()
	return self._startPos <= posX and posX <= self._endPos
end

function ClassRef:setBlessExp(exp)
	self.blessExp = exp
end

function ClassRef:getBlessExp()
	return self.blessExp, self.blessExpMax
end

-- TODO
function ClassRef:getBlessLev()
	return 1
end

function ClassRef:getUDFame()
	return UD:getFameWithId(self._conf.fameID)
end

function ClassRef:getFame()
	if not self._fame then
		local ary = table.tonumber(string.split(self._conf.blessingFame, "|"))
		local fame = Fame.new()
		fame:read({uid=ary[1], level=1, exp=0})
		fame:setAmount(ary[2])
		self._fame = fame
	end
	return self._fame
end

function ClassRef:getOwnerStr()
	return L("lua_code_text_210")
end

-- npc列表
function ClassRef:getNpcs()
	if not self._npcs then
		local retNpcs = {}
		if self._conf.districtNpc then
			local npcs = string.split(self._conf.districtNpc, ";")
			for i,v in ipairs(npcs) do
				local conf = GD:queryMapNpc(v)
				retNpcs[#retNpcs + 1] = {id=tonumber(v), name=L(conf.name or v)}
			end
		end
		self._npcs = retNpcs
	end
	return self._npcs
end

-- 区域出生点，移动到该区域时即移动到出生点
function ClassRef:getResetPos()
	return self._resetPos
end

function ClassRef:getName()
	return L(self._conf.name)
end

function ClassRef:getDesc()
	return L(self._conf.des)
end

function ClassRef:getIcon()
	if not self._icon then
		self._icon = table.concat({"art/district_map/", self._conf.icon or "", ".png"})
	end
	return self._icon
end

function ClassRef:getBg()
	if not self._bg then
		self._bg = table.concat({"art/map/", self._conf.background, ".png"})
	end
	return self._bg
end


return ClassRef